<!--
  - Copyright (c) 2018.
  - 北京九思金信科技有限公司对该文件内容保留所有权利。
  - 未经许可，不得私自拷贝、传播、发布、引用该文件内容，违者将被追究法律责任。
  -->

<template>
  <el-submenu class="joys-menu" :class="'level'+level" v-if="menu.children" :index="menu.menuItemId"
              popper-class="joys-menu-pop">
    <div slot="title" class="more-space" :style="{marginLeft:(-20*level+20)+'px'}">
      <i class="submenu-icon" :class="getIconClass()"></i>
      <span class="submenu_icon">{{menu.menuItemName}}</span>
    </div>
    <menu-node v-for="child in menu.children" :key="child.menuItemId" :menu="child" :level="level+1"></menu-node>
  </el-submenu>
  <el-menu-item class="joys-menu" :class="'level'+level" v-else :index="menu.appletId">
    <div class="more-space" :style="{marginLeft:(-20*level+20)+'px'}">
      <i class="submenu-icon" :class="getIconClass()"/>
      <span class="submenu_icon_item">{{menu.menuItemName}}</span>
    </div>
  </el-menu-item>
</template>

<script>
  export default {
    name: 'MenuNode',
    props: ['menu', 'level'],
    methods: {
      getIconClass() {
        let iconClass = null
        if (this.level == 1) {
          iconClass = 'submenu-icon level1 ' + this.menu.iconClass
        } else if (this.level == 2) {
          iconClass = 'submenu-icon level2 joys-icon-secondary-nav'
        } else {
          iconClass = 'submenu-icon level3 joys-icon-secondary-nav'
        }
        return iconClass
      },
      getRoute() {
        return '/applets/' + this.menu.appletId
      }
    }
  }
</script>
<style>
  .joys-menu, .joys-menu-pop.el-menu {
    background-color: #fff;
    color: #C0C1C4;
  }

  .joys-menu .el-menu-item, .joys-menu-pop .el-menu-item {
    color: #C0C1C4;
  }

  .joys-menu-pop .el-menu--popup-right-start {
    margin: 0;
  }

  .joys-menu-pop .el-menu--popup {
    padding: 0;
  }

  .joys-menu .el-menu-item:hover .submenu-icon, .joys-menu-pop .el-menu-item:hover .submenu-icon {
    color: #ffffff;
  }

  .joys-menu.el-submenu.is-opened .el-submenu__title:hover, .joys-menu-pop .is-opened .el-submenu__title:hover {
    background-color: #999;
  }

  .joys-menu.el-submenu .el-submenu__title:hover, .joys-menu-pop .el-submenu__title:hover, .joys-menu.el-menu-item:hover, .joys-menu-pop .el-menu-item:hover {
    background-color: #999;
  }

  .joys-menu .is-active, .joys-menu .is-active:hover, .joys-menu-pop .is-active, .joys-menu-pop .is-active:hover {
    background-color: #bbb;
    color: #ffffff;
  }

  .joys-menu.level1 .el-submenu__title, .joys-menu.level1.el-menu-item, .joys-menu-pop.level1.el-menu-item {
    height: 88px !important;
    line-height: 88px;
  }

  .joys-menu.level2 .el-submenu__title, .joys-menu.level2.el-menu-item, .joys-menu-pop.level1.el-menu-item {
    height: 72px !important;
    line-height: 72px;
  }

  .joys-menu.level3 .el-submenu__title, .joys-menu.level3.el-menu-item, .joys-menu-pop.level1.el-menu-item {
    height: 72px;
    line-height: 72px;
  }
</style>
<style scoped>
  .submenu-icon {
    margin-right: 5px;
    vertical-align: middle;
    font-family: PingFangSC-Medium;
  }

  .submenu_icon {

    font-size: 14px;
    color: #555C62;
    letter-spacing: 0;
    line-height: 22px;
  }

  .submenu_icon_item {
    font-family: PingFangSC-Light;
    font-size: 12px;
    color: #555C62;
    letter-spacing: 0;
    line-height: 20px;
  }

  .submenu-icon.level1 {
    font-size: 16px;
  }

  .submenu-icon.level2 {
    font-size: 16px;
    width: 4px;
    height: 4px;
    margin: 6px 6px;
    overflow: hidden;
  }

  .submenu-icon.level3 {
    font-size: 16px;
    width: 4px;
    height: 4px;
    margin: 6px 6px;
    overflow: hidden;
  }

  .more-space {
    padding-left: 15px;
  }

  .el-submenu.is-opened {
    background-color: #999;
  }

</style>
